package leetcode.editor.cn;

public class _141_LinkedListCycle {
    public static void main(String[] args) {
        Solution solution = new _141_LinkedListCycle().new Solution();
    }

    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    public class Solution {
        public boolean hasCycle(ListNode head) {
            if (head == null) return false;
            ListNode slow = head, fast = head;
            while (fast.next != null && fast.next.next != null) {
                fast = fast.next.next;
                slow = slow.next;
                if (slow == fast) return true;
            }
            return false;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}